#include "EpilForNumberStatementCode.h"
#include "EpilOutputHelper.h"
#include "TCharSupport.h"
#include "EpilPointerHelper.h"


EpilForNumberStatementCode::EpilForNumberStatementCode( const EpilLexLocation & location )
: EpilForStatementCodeBase( location )
, m_begin( NULL )
, m_end( NULL )
, m_step( NULL )
, m_variable( t("") )
{
}


EpilForNumberStatementCode::~EpilForNumberStatementCode()
{
	EpilPointerHelper::SafeDelete( m_begin );
	EpilPointerHelper::SafeDelete( m_end );
	EpilPointerHelper::SafeDelete( m_step );
}


tstring EpilForNumberStatementCode::ToEpilCode( int indent ) const
{
	tstringstream ret;
	ret << EpilOutputHelper::GetIndent( indent );
	ret << t("for ");
	ret << m_variable;
	ret << t(" = ");
	ret << m_begin->ToEpilCode();
	ret << t(", ");
	ret << m_end->ToEpilCode();
	if( m_step )
	{
		ret << t(", ");
		ret << m_step->ToEpilCode();
	}
	ret << t(" do");
	ret << endl;
	ret << this->GetBlock()->ToEpilCode( indent + 1 );
	ret << endl;
	ret << EpilOutputHelper::GetIndent( indent );
	ret << t("end");
	return ret.str();
}